let app = getApp();
Page({
  data: {
    indexImg: [], 
    indicatorDots: true,
    vertical: true,
    autoplay: true,
    interval: 3000,
    duration: 500
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  onLoad(){
    app.post("indexImages").then((res)=>{
      this.setData({
        indexImg:res.data
      });
    })
  },
  swiperTap(e){
    let { linkurl } = e.currentTarget.dataset;
    console.log(linkurl)
    if (linkurl){
      let qs = linkurl.split(":");
      if (qs.length == 2){
        switch (qs[0]){
          case "https":
            let url = encodeURIComponent(linkurl);
            console.log(url);
            wx.navigateTo({
              url: `/pages/webview/webview?url=${url}`,
            })
          break;
          case "goods":
            wx.navigateTo({
              url: `/pages/logs/logs?id=${qs[1]}`,
            })
          break;
          default:
          break;
        }
      }
    }
  },
  onShareAppMessage(){
    
  }
});

function CurrentTime(year, month, day, hour, minute, second) {
  var Current = (new Date(year, month - 1, day, hour, minute, second)) - (new Date()); //计算剩余的毫秒数 
  var days = parseInt(Current / 1000 / 60 / 60 / 24, 10); //计算剩余的天数 
  var hours = parseInt(Current / 1000 / 60 / 60 % 24, 10); //计算剩余的小时 
  var minutes = parseInt(Current / 1000 / 60 % 60, 10);//计算剩余的分钟 
  var seconds = parseInt(Current / 1000 % 60, 10);//计算剩余的秒数 
  var str = '';
  days = checkTime(days);
  hours = checkTime(hours);
  minutes = checkTime(minutes);
  seconds = checkTime(seconds);
  setInterval(function(){
    CurrentTime(2019, 11, 11, 11, 11, 11);
  }, 1000);
  str = days + "天" + hours + "小时" + minutes + "分" + seconds + "秒"
}; 
function checkTime(i) {
  if (i < 10) {
    i = "0" + i;
  }
  return i;
}